package br.uniriotec.pssgbd.unterhaltung.view.controle;

import java.util.List;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.uniriotec.pssgbd.unterhaltung.model.bo.RelatorioDegustacaoBO;
import br.uniriotec.pssgbd.unterhaltung.model.bo.RotuloBO;
import br.uniriotec.pssgbd.unterhaltung.model.entidade.Rotulo;
import br.uniriotec.pssgbd.unterhaltung.model.entidade.relacionadaDegustacao.ResultadoRelatorioDegustacao;

public class RelatorioDegustacaoServlet extends  HttpServlet{
	
	private static final long serialVersionUID = 1L;

	public RelatorioDegustacaoServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws  ServletException, IOException{
		try {
			List<ResultadoRelatorioDegustacao> listaInfoDegustacoes = getRelatorioDegustacaoInstance().listar();
			request.setAttribute("listaInfoDegustacoes", listaInfoDegustacoes);

			RequestDispatcher rd = request
					.getRequestDispatcher("listarDegustacoes.jsp");
			fowardPage(request, response, rd);

		} catch (Exception e) {
			final String mensagemErro = "erroGeralRotulo.jsp?tituloPagina=Listar Degustacoes&mensagem=Erro na listagem de degustacoes! Detalhe: ";
			response.sendRedirect(getMensagemErro(e, mensagemErro));
		}

	}

	private RelatorioDegustacaoBO getRelatorioDegustacaoInstance() {
		return RelatorioDegustacaoBO.getInstance();
	}
	
	private void fowardPage(HttpServletRequest request,
			HttpServletResponse response, RequestDispatcher rd)
			throws ServletException, IOException {
		rd.forward(request, response);
	}
	
	private String getMensagemErro(Exception e, final String mensagemErro) {
		return mensagemErro + e.getMessage();
	}
	
	
}
